package org.gwt.grin.client.commands;

import java.util.Map;

import org.gwt.grin.client.Feature;
import org.gwt.grin.client.Show;
import org.gwt.grin.client.features.Assembly;

public class ActivatePartCommand extends Command {
	
	protected Assembly assembly;
	protected Feature part;
	
	public ActivatePartCommand(Show show) {
		super(show);
	}
	
	public ActivatePartCommand(Show show, Assembly assembly, Feature part) {
		super(show);
		setup(assembly, part);
	}
	
	public void setup(Assembly assembly, Feature part) {
		this.assembly = assembly;
		this.part = part;
	}
	
	@Override
	public Command cloneIfNeeded(Map<Feature, Feature> featureClones) {
		Assembly assemblyClone = (Assembly) featureClones.get(assembly);
		if (assemblyClone == null) {
		    return this;
		}
		Feature partClone = (Feature) featureClones.get(part);
		assert partClone != null;
		return new ActivatePartCommand(show, assemblyClone, partClone);
	}
	
	public Assembly getAssembly() {
		return assembly;
	}

	public Feature getPart() {
		return part;
	}

	@Override
	public void execute() {
		assembly.setCurrentPart(part);
	}

}
